import searchDao from '../dao/SearchDao'

class SearchService {
  static searchService = new SearchService()
  async addOrUpdateHistoryKeyWord(historyKeyWord: string) {
    const dbHistoryKeyWord = await searchDao.searchHistoryKeyWords(historyKeyWord)
    if (dbHistoryKeyWord) {
      const result: [{ affectedRows: number }, any] = await searchDao.updateHistoryKeyWordCount(historyKeyWord)
      return result[0].affectedRows
    } else {
      const result: [number, number] = await searchDao.saveHistoryKeyWords(historyKeyWord)
      return result[0]
    }
  }
  async searchKeyWords(key: string) {
    return await searchDao.searchKeyWords(key)
  }
  async getHistoryKeyWordsList() {
    return await searchDao.getHistoryKeyWordsList()
  }
  async searchDecovery() {
    return await searchDao.searchDecovery()
  }
  async deleteHistoryKeyWord(id: number) {
    return await searchDao.deleteHistoryKeyWord(id)
  }
}

export default SearchService.searchService
